package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.BreedTransferRecordManager;
import com.jiantong.work.model.BreedTransferRecord;
import com.jiantong.work.service.BreedTransferRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by mz on 14/8/17.
 * 转群写服务的实现
 */
@Slf4j
@Service
@RpcProvider
public class BreedTransferRecordWriteServiceImpl implements BreedTransferRecordWriteService{

    private final BreedTransferRecordManager breedTransferRecordManager;

    @Autowired
    public BreedTransferRecordWriteServiceImpl(BreedTransferRecordManager breedTransferRecordManager) {
        this.breedTransferRecordManager = breedTransferRecordManager;
    }

    /**
     * 添加一条转群记录
     *
     * @param breedTransferRecord 转群记录对象
     * @param toStatus            到状态
     * @return Long 主键ID
     */
    @Override
    public Response<Long> create(BreedTransferRecord breedTransferRecord, Integer toStatus) {
        try{
            return Response.ok(breedTransferRecordManager.createBreedTransferRecord(breedTransferRecord,toStatus));
        }catch (Exception e){
            log.error("failed to create breed transfer record , case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to create breed transfer record");
        }
    }

    /**
     * 更新一条转群记录
     *
     * @param breedTransferRecord 转群记录对象
     * @param toStatus            到状态
     * @return Boolean 是否更新成功
     */
    @Override
    public Response<Boolean> update(BreedTransferRecord breedTransferRecord, Integer toStatus) {
        try{
            return Response.ok(breedTransferRecordManager.updateBreedTransferRecord(breedTransferRecord,toStatus));
        }catch (Exception e){
            log.error("failed to update breed transfer record , case = {}", Throwables.getStackTraceAsString(e));
            return Response.fail("failed to update breed transfer record");
        }
    }
}
